package com.sf.iisp.kafka.listener;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.sf.kafka.api.consume.IStringMessageConsumeListener;
import com.sf.kafka.api.consume.KafkaConsumeRetryException;
import com.sf.kafka.check.util.JsonUtil;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * Created by qi on 16-7-19.
 */
public abstract class AbstractListener implements IStringMessageConsumeListener {

    static {
        JsonUtil.getMapper().setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        JsonUtil.getMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    }

    @Override
    public void onMessage(List<String> msgs) throws KafkaConsumeRetryException {
        if (msgs != null) {
            handle(msgs);
        }
    }

    public abstract void handle(List<String> msgs) throws KafkaConsumeRetryException;

}
